var do_Page = sm("do_Page");
var do_App = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");

var pub = require("url/pub");
var qqHttp = require("helper/http");

//声明UI变量
var listview=ui("listview");
var listdata = mm("do_ListData");
listview.bindItems(listdata);//绑定item的数据
var noData = [{"template":1,"labelContent":"没有收到新的点赞"}];
//本页面-ajax业务请求url
var httpUrl = pub.url.praise.praise2me;
/****************处理页面-头部-begin*****************/
var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
//左上角-返回
ui(addheader+".headerLeft").on("touch", function() {
	do_App.closePage()
});

//头部标题
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({"labelTitle" : "点赞"});
header.refreshData();
/****************处理页面-头部-end*****************/
//andriod返回键
do_Page.on("back", function() {
    do_App.closePage();
});


//从新增页面返回,刷新数据
do_Page.on("result", function(data){
    binddata();
});

var count = null;//查询最新的条数
//当页面加载完毕后执行
do_Page.on("loaded", function() {
	count = do_Page.getData().count;
	binddata();
});

//全部刷新数据
function binddata(){
	var params={"count":count};
	qqHttp.post(httpUrl,params,function(data){
		var praiseList = data.praiseList;
		listview.rebound();
		listdata.removeAll();
		if(praiseList!=null && praiseList.length>0){
			for(var i in praiseList){
				praiseList[i].isNew = true;//是否新的点赞
			}
			listdata.addData(praiseList);
		}
		else{
			listdata.addData(noData);
		}
		listview.refreshItems();//刷新item数据
	});
}

//下拉列表，刷新数据
listview.on("pull", function(data){
	if (data.state == 2){
		binddata();
	}
});

//上拉列表，翻页数据
listview.on("push", function(data){
	if (data.state == 2){
		binddata();
	}
});
